pull-local: Output status even in non-tty case
authorColin Walters <walters@verbum.org>
Thu, 21 Feb 2013 13:54:13 +0000 (08:54 -0500)
committerColin Walters <walters@verbum.org>
Thu, 21 Feb 2013 13:54:13 +0000 (08:54 -0500)
This way I can see progress when running builddisks.

src/ostree/ot-builtin-pull-local.c

index 81c6d889e4f87f722cb29b1adaf77b47983e58c8..5c1106bce76b7a0fe4a6454cf1c531fcf3388518 100644 (file)
@@ -40,6 +40,7 @@ typedef struct {
   int n_objects_to_check;
   volatile int n_objects_checked;
   volatile int n_objects_copied;
+  GSConsole *console;
 } OtLocalCloneData;
 
 static gboolean
@@ -141,7 +142,10 @@ idle_print_status (gpointer user_data)
                          g_atomic_int_get (&data->n_objects_checked),
                          data->n_objects_to_check,
                          g_atomic_int_get (&data->n_objects_copied));
-  gs_console_begin_status_line (gs_console_get (), str, NULL, NULL);
+  if (data->console)
+    gs_console_begin_status_line (data->console, str, NULL, NULL);
+  else
+    g_print ("%s\n", str);
 
   return TRUE;
 }
@@ -269,26 +273,19 @@ ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GError **err
 
   if (data->n_objects_to_check > 0)
     {
-      console = gs_console_get ();
+      data->console = gs_console_get ();
+
+      if (data->console)
+        gs_console_begin_status_line (console, "", NULL, NULL);
+
+      g_timeout_add_seconds (1, idle_print_status, data);
+      idle_print_status (data);
 
-      if (console)
-        {
-          gs_console_begin_status_line (console, "", NULL, NULL);
-          g_timeout_add_seconds (1, idle_print_status, data);
-          idle_print_status (data);
-        }
-      else
-        {
-          g_print ("Copying %d objects...\n", data->n_objects_to_check);
-        }
-      
       g_main_loop_run (data->loop);
 
-      if (console)
-        {
-          idle_print_status (data);
-          gs_console_end_status_line (console, NULL, NULL);
-        }
+      idle_print_status (data);
+      if (data->console)
+        gs_console_end_status_line (console, NULL, NULL);
     }
 
   if (!ostree_repo_commit_transaction (data->dest_repo, NULL, error))